import request from '@/utils/request.js'

/**
 * 用户接口
 *
 * @method getPage 获取用户分页列表
 * @method save 保存用户
 * @method update 修改用户
 * @method updateProfile 修改个人资料
 * @method updatePassword 修改密码
 * @method remove 删除用户
 * @method getById 根据ID查询
 * @method assignRole 分配角色
 */
export function useUserApi() {
  const basePath = '/admin/user'

  const getPage = (params, data) => {
    return request({
      url: `${basePath}/page`,
      method: 'post',
      params,
      data
    })
  }

  const save = (data) => {
    return request({
      url: `${basePath}/save`,
      method: 'post',
      data
    })
  }

  const update = (data) => {
    return request({
      url: `${basePath}/update`,
      method: 'put',
      data
    })
  }

  const updateProfile = (data) => {
    return request({
      url: `${basePath}/update-profile`,
      method: 'put',
      data
    })
  }

  const updatePassword = (data) => {
    return request({
      url: `${basePath}/update-password`,
      method: 'put',
      data
    })
  }

  const remove = (data) => {
    return request({
      url: `${basePath}/delete`,
      method: 'delete',
      data
    })
  }

  const getById = (id) => {
    return request({
      url: `${basePath}/get/${id}`,
      method: 'get'
    })
  }

  const assignRole = (data) => {
    return request({
      url: `${basePath}/assign-role`,
      method: 'put',
      data
    })
  }

  return {
    getPage,
    save,
    update,
    updateProfile,
    updatePassword,
    remove,
    getById,
    assignRole
  }
}
